package cn.yangliu.web;

import cn.yangliu.comm.BaseComponent;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * 作者 杨柳
 * 创建时间 2017-08-29 10:15
 */

/**
 * 异步方法 带返回值
 */
@Component
public class AsyncTask2 extends BaseComponent {

    @Async
    public Future<String> test1() {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {}
        logger.info(Thread.currentThread().getId()+"返回值任务1成功");
        return new AsyncResult<>("1");
    }
    @Async
    public Future<String> test2() {
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {}
        logger.info(Thread.currentThread().getId()+"返回值任务2成功");

        return new AsyncResult<>("2");
    }
    @Async
    public Future<String> test3() {
        try {
            Thread.sleep(3000L);
        } catch (InterruptedException e) {}
        logger.info(Thread.currentThread().getId()+"返回值任务3成功");
        return new AsyncResult<>("3");
    }
}
